<?php

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

require __DIR__ . '/../../vendor/autoload.php';

$config = require(__DIR__ . '/../config.php');
$connection = new AMQPStreamConnection(
    $config['host'],
    $config['port'],
    $config['user'],
    $config['password'],
    $config['vhost']
);

$channel = $connection->channel();

const NORMAL_EXCHANE = 'normal_exchange';
$channel->exchange_declare(NORMAL_EXCHANE, 'direct');


foreach(range(0, 10) as $index) {

    $msg = new AMQPMessage('ttl' . $index);
    echo  "msg" . $index . PHP_EOL;

    if($index < 4) {
        $channel->basic_publish($msg, NORMAL_EXCHANE, 'rk_a');
        continue;
    }

    if($index < 7) {
        $channel->basic_publish($msg, NORMAL_EXCHANE, 'rk_b');
        continue;
    }

    if($index < 11) {
        $msg2 = new AMQPMessage('ttl30' . $index, [
            'expiration' => 30
        ]);
        $channel->basic_publish($msg2, NORMAL_EXCHANE, 'rk_qc');
        continue;
    }
}

echo "done";